﻿//////////////////////////////////////////////////////////////////////////////
//
// Copyright © 1998-2024 Glodon Company Limited.
//
// Licensed under the MIT License
//
// Permission is hereby granted, free of charge, to any person obtaining a
// copy of this software and associated documentation files (the “Software”),
// to deal in the Software without restriction, including without limitation
// the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
// sell copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
//////////////////////////////////////////////////////////////////////////////
#include "ColorSettingInquiryDialog.h"
#include <qpushbutton.h>
#include <QColorDialog>
#include "GbmpNew.h"
#include "TranslatorManager.h"
#include "EnableCompileWarning_The_LAST_IncludeInCpp.h"

ColorSettingInquiryDialog::ColorSettingInquiryDialog(const QColor& initialColor, QWidget *parent)
    : QDialog(parent)
    , m_isToOverrideColor(true)
    , m_color(initialColor)
{
    setWindowTitle(QString::fromStdWString(GBMP_TR(L"请选择操作")));
    setObjectName(QString::fromStdWString(L"ColorSettingInquiryDialog"));

    int btnWidth = 80;
    int btnHeight= 30;
    int btnGapHori = 20;
    int btnGapVert = 10;

    int dlgWidth = btnWidth * 2 + btnGapHori * 3;
    int dlgHeight= btnHeight + btnGapVert * 2;

    this->setFixedSize(dlgWidth, dlgHeight);

    QPushButton *noOverrideColorBtn = NEW_AS_QT_CHILD(QPushButton, this);
    noOverrideColorBtn->setObjectName(QString::fromStdWString(L"noOverrideColorBtn"));
    noOverrideColorBtn->setText(QString::fromStdWString(GBMP_TR(L"无替换")));
    noOverrideColorBtn->setGeometry(QRect(btnGapHori, btnGapVert, btnWidth, btnHeight));
    QObject::connect(noOverrideColorBtn, SIGNAL(clicked()), this, SLOT(NoOverrideButtonClicked()));

    QPushButton *settingColorBtn = NEW_AS_QT_CHILD(QPushButton, this);
    settingColorBtn->setObjectName(QString::fromStdWString(L"settingColorBtn"));
    settingColorBtn->setText(QString::fromStdWString(GBMP_TR(L"设置颜色")));
    settingColorBtn->setGeometry(QRect(btnGapHori*2 + btnWidth, btnGapVert, btnWidth, btnHeight));
    QObject::connect(settingColorBtn, SIGNAL(clicked()), this, SLOT(SettingColorButtonClicked()));
}

void ColorSettingInquiryDialog::NoOverrideButtonClicked()
{
    m_isToOverrideColor = false;
    QDialog::accept();
}

void ColorSettingInquiryDialog::SettingColorButtonClicked()
{
    QColorDialog qcolorDialog;
    QColor resColor = qcolorDialog.getColor(m_color,this);
    if (!resColor.isValid())
    {
        QDialog::reject();
        return;
    }

    m_color = resColor;     

    QDialog::accept();
}
